package csci5115.autoalarm;

import android.app.AlertDialog;
import android.app.TabActivity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.widget.TabHost;

public class AutoAlarmActivity extends TabActivity {
	/** Called when the activity is first created. */

	public static TabHost tabHost;
	SharedPreferences mPrefs;
	final String welcomeScreenShownPref = "welcomeScreenShown";
	Context mCtx;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		mCtx = this;
		// Welcome Screen
		mPrefs = PreferenceManager.getDefaultSharedPreferences(this);

		// second argument is the default to use if the preference can't be
		// found
		Boolean welcomeScreenShown = mPrefs.getBoolean(welcomeScreenShownPref,
				false);

		if (!welcomeScreenShown) {

			String whatsNewTitle = "Welcome To Auto-Alarm";
			String whatsNewText = "It is recommended to sync Auto-Alarm with your Google Calendar for best effect.";
			new AlertDialog.Builder(this)
					.setIcon(android.R.drawable.ic_dialog_alert)
					.setTitle(whatsNewTitle)
					.setMessage(whatsNewText)
					.setPositiveButton("Do This Now",
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int which) {
									Intent myIntent = new Intent(mCtx,
											AccountLoginActivity.class);
									startActivityForResult(myIntent, 0);
									dialog.dismiss();
								}
							})
					.setNegativeButton("Later",
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int which) {
									dialog.dismiss();
								}
							}).show();
			SharedPreferences.Editor editor = mPrefs.edit();
			editor.putBoolean(welcomeScreenShownPref, true);
			editor.commit();
		}

		tabHost = getTabHost();
		TabHost.TabSpec spec;
		Intent intent;

		// Tab 1
		intent = new Intent().setClass(this, CalendarViewActivity.class);
		spec = tabHost.newTabSpec("monthview").setIndicator("Month")
				.setContent(intent);
		tabHost.addTab(spec);

		// Tab 2
		intent = new Intent().setClass(this, NewDayView.class);
		spec = tabHost.newTabSpec("dayview").setIndicator("Day")
				.setContent(intent);
		tabHost.addTab(spec);

		// Tab 3
		intent = new Intent().setClass(this, ListViewActivity.class);
		spec = tabHost.newTabSpec("listview").setIndicator("List")
				.setContent(intent);
		tabHost.addTab(spec);

		// Tab 4
		intent = new Intent().setClass(this, SettingsTabActivity.class);
		spec = tabHost.newTabSpec("settingsview").setIndicator("Settings")
				.setContent(intent);
		tabHost.addTab(spec);

		/*
		 * Default tab 0 - Month 1 - Day 2 - List 3 - Settings
		 */
		tabHost.setCurrentTab(1);
	}

}